
angular.module('QualityJudge')

.factory('QualityJudgeHttpUtil', ['User', 'Device', 'Http', 'QUALITYJUDGECONSTANTS', 
    function (User, Device, Http, QUALITYJUDGECONSTANTS) {
        var o = {};

        o.queryMasters = function () {
            return Http.post({
                url: QUALITYJUDGECONSTANTS.queryBadMastersURL
            });
        };
        o.decideScanCode = function (barcode) {
            return Http.post({
                url: QUALITYJUDGECONSTANTS.decideScanCodeURL,
                data: {
                    Parameter: {
                        Barcode: barcode
                    }
                }
            });
        };
        o.doJudge = function (barcode, qcStatus) {
            var device = Device.get(),
                data = {
                Barcode: barcode,
                UserID: User.get('_id'),
                QCStatus: qcStatus
            };
            if (device.Terminal) {
                data.Terminal = device.Terminal._id;
                data.TerminalName = device.Terminal.Name;
            }
            if (device.Department) {
                data.Department = device.Department._id;
            }
            if (device.Work) {
                data.Work = device.Work._id;
            }
            return Http.post({
                url: QUALITYJUDGECONSTANTS.doJudgeURL,
                data: data
            });
        };
        o.getProductFlow = function (barcode) {
            return Http.post({
                url: QUALITYJUDGECONSTANTS.getProductFlowURL,
                data: {
                    Parameter: {
                        Barcode: barcode
                    }
                }
            });
        };

        return o;
    }
]);